home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 27 / CU Amiga Magazine's Super CD-ROM 27 (1998)(EMAP Images)(GB)[!][issue 1998-10].iso / CUCD / Utilities / SmartFilesystem / Sources / Diskspeed / diskspeed.c next >
Encoding:
C/C++ Source or Header  |  1998-06-14  |  24.9 KB  |  1,096 lines

  1. #include <devices/timer.h>
  2. #include <dos/dos.h>
  3. #include <dos/filehandler.h>
  4. #include <exec/io.h>
  5. #include <exec/memory.h>
  6. #include <exec/types.h>
  7. #include <proto/dos.h>
  8. #include <proto/exec.h>
  9. #include <proto/timer.h>
  10. #include <proto/utility.h>
  11.  
  12. #include <math.h>
  13. #include <stdio.h>
  14.  
  15. struct Library *UtilityBase;
  16. struct Library *TimerBase;
  17. struct MsgPort *msgporttimer;
  18. struct timerequest *iorequesttimer;
  19.  
  20. BPTR maindirlock;
  21. BPTR oldlock;
  22.  
  23. LONG init(void);
  24. LONG cleanup(void);
  25.  
  26. struct EClockVal starttime;
  27. struct EClockVal endtime;
  28. ULONG unit;
  29. ULONG timing;
  30.  
  31. LONG test_seekread(ULONG readsize,ULONG filesize);
  32. LONG test_read(ULONG readsize,ULONG filesize);
  33. LONG test_delayedread(ULONG readsize,ULONG filesize);
  34. LONG test_write(ULONG readsize);
  35. LONG test_stationaryread(ULONG readsize);
  36. LONG test_createfiles(void);
  37. LONG testfiles_createfiles(ULONG filesize);
  38. LONG testfiles_deletefiles(void);
  39. LONG testfiles_dirscan(void);
  40. LONG testfiles_openclose(void);
  41. LONG testfiles_load(void);
  42. LONG testfiles_lockunlock(void);
  43. LONG createtestfiles(ULONG filesize);
  44.  
  45. ULONG rangerandom(ULONG);
  46. extern ULONG __asm RANDOM(register __d0 ULONG);
  47. ULONG rndseed=1;
  48.  
  49. UBYTE string[512];
  50.  
  51. struct {char *dir;
  52.         ULONG all;
  53.         ULONG create;
  54.         ULONG delete;
  55.         ULONG dirscan;
  56.         ULONG openclose;
  57.         ULONG lockunlock;
  58.         ULONG load;
  59.         ULONG read;
  60.         ULONG write;
  61.         ULONG seek;
  62.         LONG *files;
  63.         LONG *createsize;
  64.         LONG *seeksize;
  65.         LONG *readsize;
  66.         LONG *writesize;
  67.         ULONG nounits;
  68.         ULONG verbose;} arglist={NULL};
  69.  
  70. LONG files=1000;
  71. LONG createsize=128;
  72. LONG seeksize=2048;
  73. LONG readsize=65536;
  74. LONG writesize=65536;
  75.  
  76. void main(void) {
  77.   char template[]="DIRECTORY,ALL/S,CREATE/S,DELETE/S,DIRSCAN/S,OPENCLOSE/S,LOCKUNLOCK/S,LOAD/S,READ/S,WRITE/S,SEEK/S,FILES/N,CREATESIZE/N,SEEKSIZE/N,READSIZE/N,WRITESIZE/N,NOUNITS/S,VERBOSE/S";
  78.   struct RDArgs *readarg;
  79.  
  80.   if((DOSBase=(struct DosLibrary *)OpenLibrary("dos.library",37))!=0) {
  81.     printf("Diskspeed 1.1 (1 June 1998) - Programmed by John Hendrikx\n\n");
  82.     readarg=ReadArgs(template,(LONG *)&arglist,0);
  83.     if(readarg!=0) {
  84.       WORD parametersokay=TRUE;
  85.  
  86.       if(arglist.all!=0) {
  87.         arglist.create=-1;
  88.         arglist.delete=-1;
  89.         arglist.dirscan=-1;
  90.         arglist.openclose=-1;
  91.         arglist.lockunlock=-1;
  92.         arglist.load=-1;
  93.         arglist.read=-1;
  94.         arglist.write=-1;
  95.         arglist.seek=-1;
  96.       }
  97.       else if(arglist.delete!=0 || arglist.dirscan!=0 || arglist.openclose!=0 || arglist.lockunlock!=0 || arglist.load!=0) {
  98.         arglist.create=-1;
  99.       }
  100.  
  101.       if(arglist.files!=0) {
  102.         files=*arglist.files;
  103.       }
  104.       if(arglist.createsize!=0) {
  105.         createsize=*arglist.createsize;
  106.       }
  107.       if(arglist.seeksize!=0) {
  108.         seeksize=*arglist.seeksize;
  109.       }
  110.       if(arglist.readsize!=0) {
  111.         readsize=*arglist.readsize;
  112.       }
  113.       if(arglist.writesize!=0) {
  114.         writesize=*arglist.writesize;
  115.       }
  116.  
  117.       if(files<10 || files>50000) {
  118.         parametersokay=FALSE;
  119.         printf("Illegal parameter value: files must be between 10 and 50000\n");
  120.       }
  121.  
  122.       if(createsize<0 || createsize>1024*1024) {
  123.         parametersokay=FALSE;
  124.         printf("Illegal parameter value: CREATESIZE must be between 0 and 1048576 (1 MB)\n");
  125.       }
  126.  
  127.       if(readsize<1 || readsize>1024*1024) {
  128.         parametersokay=FALSE;
  129.         printf("Illegal parameter value: READSIZE must be between 1 and 1048576 (1 MB)\n");
  130.       }
  131.  
  132.       if(writesize<1 || writesize>1024*1024) {
  133.         parametersokay=FALSE;
  134.         printf("Illegal parameter value: WRITESIZE must be between 1 and 1048576 (1 MB)\n");
  135.       }
  136.  
  137.       if(seeksize<1 || seeksize>65536) {
  138.         parametersokay=FALSE;
  139.         printf("Illegal parameter value: SEEKSIZE must be between 1 and 65536 (64 kB)\n");
  140.       }
  141.  
  142.  
  143.       if(parametersokay == TRUE && (UtilityBase=OpenLibrary("utility.library",37))!=0) {
  144.         BPTR newdirlock=0;
  145.  
  146.         if(arglist.dir!=0) {
  147.           newdirlock=Lock(arglist.dir,SHARED_LOCK);
  148.         }
  149.  
  150.         if(arglist.dir==0 || newdirlock!=0) {
  151.  
  152.           if(arglist.dir!=0) {
  153.             newdirlock=CurrentDir(newdirlock);
  154.           }
  155.  
  156.           if((msgporttimer=CreateMsgPort())!=0) {
  157.             if((iorequesttimer=CreateIORequest(msgporttimer,sizeof(struct timerequest)))!=0) {
  158.               if(OpenDevice("timer.device",UNIT_VBLANK,&iorequesttimer->tr_node,0)==0) {
  159.                 struct InfoData id;
  160.                 BPTR lock;
  161.                 UBYTE *s;
  162.                 LONG errorcode;
  163.  
  164.                 GetCurrentDirName(string,500);
  165.  
  166.                 s=string;
  167.                 while(*s!=0 && *s++!=':') {
  168.                 }
  169.                 *s=0;
  170.  
  171.                 lock=CurrentDir(0);
  172.                 Info(lock,&id);
  173.                 CurrentDir(lock);
  174.  
  175.                 printf("Volume %s %ld blocks (%ld MB), %ld bytes per block.\n",string,id.id_NumBlocks,(id.id_NumBlocks*(id.id_BytesPerBlock>>9))>>11,id.id_BytesPerBlock);
  176.                 printf("The volume has %ld buffers and the DosType is 0x%08lx.\n\n",AddBuffers(string,0),id.id_DiskType);
  177.  
  178.  
  179.                 TimerBase=(struct Library *)iorequesttimer->tr_node.io_Device;
  180.  
  181.                 init();
  182.  
  183.  
  184.  
  185.                 if(arglist.create!=0 && (errorcode=testfiles_createfiles(createsize))==0) {
  186.                   if(arglist.dirscan!=0 && (errorcode=testfiles_dirscan())!=0) {
  187.                     PrintFault(errorcode,"dirscan test failed");
  188.                   }
  189.  
  190.                   if(arglist.lockunlock!=0 && (errorcode=testfiles_lockunlock())!=0) {
  191.                     PrintFault(errorcode,"lockunlock test failed");
  192.                   }
  193.  
  194.                   if(arglist.openclose!=0 && (errorcode=testfiles_openclose())!=0) {
  195.                     PrintFault(errorcode,"openclose test failed");
  196.                   }
  197.  
  198.                   if(arglist.load!=0 && (errorcode=testfiles_load())!=0) {
  199.                     PrintFault(errorcode,"load test failed");
  200.                   }
  201.  
  202.                   if((errorcode=testfiles_deletefiles())!=0) {
  203.                     PrintFault(errorcode,"deletefiles test failed");
  204.                   }
  205.                 }
  206.                 else {
  207.                   PrintFault(errorcode,"couldn't execute files tests");
  208.                 }
  209.  
  210.  
  211.                 /*
  212.  
  213.                 if((errorcode=testfiles_createfiles(1024))==0) {
  214.                   errorcode=testfiles_lockunlock();
  215.                   if(errorcode!=0) {
  216.                     PrintFault(errorcode,"lockunlock test failed");
  217.                   }
  218.  
  219.                   errorcode=testfiles_openclose();
  220.                   if(errorcode!=0) {
  221.                     PrintFault(errorcode,"openclose test failed");
  222.                   }
  223.  
  224.                   errorcode=testfiles_load();
  225.                   if(errorcode!=0) {
  226.                     PrintFault(errorcode,"openclose test failed");
  227.                   }
  228.  
  229.                   errorcode=testfiles_deletefiles();
  230.                   if(errorcode!=0) {
  231.                     PrintFault(errorcode,"deletefiles test failed");
  232.                   }
  233.                 }
  234.                 else {
  235.                   PrintFault(errorcode,"couldn't execute files tests");
  236.                 }
  237.  
  238.  
  239.  
  240.                 if((errorcode=testfiles_createfiles(8192))==0) {
  241.                   errorcode=testfiles_lockunlock();
  242.                   if(errorcode!=0) {
  243.                     PrintFault(errorcode,"lockunlock test failed");
  244.                   }
  245.  
  246.                   errorcode=testfiles_openclose();
  247.                   if(errorcode!=0) {
  248.                     PrintFault(errorcode,"openclose test failed");
  249.                   }
  250.  
  251.                   errorcode=testfiles_load();
  252.                   if(errorcode!=0) {
  253.                     PrintFault(errorcode,"openclose test failed");
  254.                   }
  255.  
  256.                   errorcode=testfiles_deletefiles();
  257.                   if(errorcode!=0) {
  258.                     PrintFault(errorcode,"deletefiles test failed");
  259.                   }
  260.                 }
  261.                 else {
  262.                   PrintFault(errorcode,"couldn't execute files tests");
  263.                 }
  264.  
  265.                 */
  266.  
  267.                 if(arglist.seek!=0 && (errorcode=test_seekread(seeksize,2*1024*1024))!=0) {
  268.                   PrintFault(errorcode,"seek/read test failed");
  269.                 }
  270.  
  271.  
  272.                 if(arglist.read!=0 && (errorcode=test_read(readsize,2*1024*1024))!=0) {
  273.                   PrintFault(errorcode,"read test failed");
  274.                 }
  275.  
  276.                 /*
  277.  
  278.                 errorcode=test_read(4096,2*1024*1024);
  279.                 if(errorcode!=0) {
  280.                   PrintFault(errorcode,"read test failed");
  281.                 }
  282.  
  283.  
  284.                 errorcode=test_read(32768,2*1024*1024);
  285.                 if(errorcode!=0) {
  286.                   PrintFault(errorcode,"read test failed");
  287.                 }
  288.  
  289.  
  290.                 errorcode=test_read(262144,2*1024*1024);
  291.                 if(errorcode!=0) {
  292.                   PrintFault(errorcode,"read test failed");
  293.                 }
  294.  
  295.                 */
  296.  
  297.                 /*
  298.  
  299.                 errorcode=test_stationaryread(262144);
  300.                 if(errorcode!=0) {
  301.                   PrintFault(errorcode,"stationary read test failed");
  302.                 }
  303.  
  304.                 */
  305.  
  306.                 if(arglist.write!=0 && (errorcode=test_write(writesize))!=0) {
  307.                   PrintFault(errorcode,"write test failed");
  308.                 }
  309.  
  310.                 /*
  311.  
  312.                 errorcode=test_write(4096);
  313.                 if(errorcode!=0) {
  314.                   PrintFault(errorcode,"write test failed");
  315.                 }
  316.  
  317.                 errorcode=test_write(32768);
  318.                 if(errorcode!=0) {
  319.                   PrintFault(errorcode,"write test failed");
  320.                 }
  321.  
  322.                 errorcode=test_write(262144);
  323.                 if(errorcode!=0) {
  324.                   PrintFault(errorcode,"write test failed");
  325.                 }
  326.  
  327.                 */
  328.  
  329.                 cleanup();
  330.  
  331.                 CloseDevice(&iorequesttimer->tr_node);
  332.               }
  333.               DeleteIORequest(iorequesttimer);
  334.             }
  335.             DeleteMsgPort(msgporttimer);
  336.           }
  337.  
  338.           if(arglist.dir!=0) {
  339.             newdirlock=CurrentDir(newdirlock);
  340.           }
  341.         }
  342.         else {
  343.           PutStr("Specified directory couldn't be locked!\n");
  344.         }
  345.         CloseLibrary((struct Library *)UtilityBase);
  346.       }
  347.       FreeArgs(readarg);
  348.     }
  349.     CloseLibrary((struct Library *)DOSBase);
  350.   }
  351. }
  352.  
  353.  
  354.  
  355. ULONG rangerandom(ULONG range) {
  356.   rndseed=RANDOM(rndseed);
  357.   return(rndseed%range);
  358. }
  359.  
  360.  
  361.  
  362. LONG init() {
  363.   if((maindirlock=CreateDir("_test_directory_"))!=0) {
  364.     oldlock=CurrentDir(maindirlock);
  365.     return(0);
  366.   }
  367.   return(IoErr());
  368. }
  369.  
  370.  
  371.  
  372. LONG cleanup() {
  373.   CurrentDir(oldlock);
  374.   UnLock(maindirlock);
  375.   if(DeleteFile("_test_directory_")==DOSFALSE) {
  376.     return(IoErr());
  377.   }
  378.   return(0);
  379. }
  380.  
  381.  
  382.  
  383. void starttimer(void) {
  384.   Delay(5*50);
  385.  
  386.   rndseed=1;
  387.   unit=ReadEClock(&starttime);
  388. }
  389.  
  390.  
  391.  
  392. LONG finished(void) {
  393.   ULONG diff;
  394.  
  395.   ReadEClock(&endtime);
  396.   diff=endtime.ev_lo-starttime.ev_lo;
  397.  
  398.   if(diff/unit>=8) {
  399.     timing=diff/unit*1000+(diff%unit * 1000)/unit;
  400.     return(TRUE);
  401.   }
  402.   return(FALSE);
  403. }
  404.  
  405.  
  406.  
  407. void endtimer(void) {
  408.   ULONG diff;
  409.  
  410.   ReadEClock(&endtime);
  411.   diff=endtime.ev_lo-starttime.ev_lo;
  412.  
  413.   timing=diff/unit*1000+(diff%unit * 1000)/unit;
  414. }
  415.  
  416.  
  417.  
  418. LONG extendfile(BPTR fh,ULONG bytes) {
  419.   LONG errorcode=0;
  420.   UBYTE *mem;
  421.  
  422.   if((mem=AllocVec(131072,MEMF_CLEAR))!=0) {
  423.     ULONG bytestowrite;
  424.  
  425.     while(bytes>0) {
  426.       bytestowrite=bytes;
  427.       if(bytestowrite>131072) {
  428.         bytestowrite=131072;
  429.       }
  430.  
  431.       if(Write(fh,mem,bytestowrite)!=bytestowrite) {
  432.         errorcode=IoErr();
  433.         break;
  434.       }
  435.  
  436.       bytes-=bytestowrite;
  437.     }
  438.  
  439.     FreeVec(mem);
  440.  
  441.     if(errorcode==0) {
  442.       if(Seek(fh,0,OFFSET_BEGINNING)==-1) {
  443.         errorcode=IoErr();
  444.       }
  445.     }
  446.   }
  447.  
  448.   return(errorcode);
  449. }
  450.  
  451.  
  452.  
  453. LONG deletetestfiles(void) {
  454.   ULONG files2=files+1;
  455.   UBYTE filename[16];
  456.  
  457.   while(--files2>0) {
  458.     sprintf(filename,"tf%06ld.tst",files2);
  459.     filename[12]=0;
  460.     DeleteFile(filename);
  461.   };
  462.  
  463.   return(0);
  464. }
  465.  
  466.  
  467.  
  468. LONG createtestfiles(ULONG filesize) {
  469.   LONG errorcode=0;
  470.   BPTR fh;
  471.   ULONG files2=files+1;
  472.   UBYTE filename[16];
  473.  
  474.   while(--files2>0) {
  475.     sprintf(filename,"tf%06ld.tst",files2);
  476.     filename[12]=0;
  477.  
  478.     if((fh=Open(filename,MODE_NEWFILE))==0) {
  479.       errorcode=IoErr();
  480.       break;
  481.     }
  482.  
  483.     if(filesize!=0) {
  484.       if((errorcode=extendfile(fh,filesize))!=0) {
  485.         Close(fh);
  486.         break;
  487.       }
  488.     }
  489.  
  490.     Close(fh);
  491.   }
  492.  
  493.   if(errorcode!=0) {
  494.     deletetestfiles();
  495.   }
  496.  
  497.   return(errorcode);
  498. }
  499.  
  500.  
  501.  
  502. LONG test_seekread(ULONG readsize,ULONG filesize) {
  503.   LONG errorcode=0;
  504.   UBYTE *mem;
  505.   BPTR fh;
  506.  
  507.   if(filesize<=readsize) {
  508.     return(ERROR_NO_FREE_STORE);
  509.   }
  510.  
  511.   if((mem=AllocVec(readsize,0))!=0) {
  512.     if((fh=Open("seekread.tst",MODE_NEWFILE))!=0) {
  513.       if((errorcode=extendfile(fh,filesize))==0) {
  514.         ULONG seekreads=0;
  515.  
  516.         starttimer();
  517.  
  518.         do {
  519.           if(Seek(fh,rangerandom(filesize-readsize),OFFSET_BEGINNING)==-1) {
  520.             errorcode=IoErr();
  521.             break;
  522.           }
  523.  
  524.           if(Read(fh,mem,readsize)!=readsize) {
  525.             errorcode=IoErr();
  526.             break;
  527.           }
  528.  
  529.           seekreads++;
  530.         } while(finished()==FALSE);
  531.  
  532.         if(errorcode==0) {
  533.           if(arglist.verbose!=0) {
  534.             printf("Seek&Read  : Seeks to random locations in a file of %ld bytes & reads %ld bytes.\n",filesize,readsize);
  535.             printf("             %ld seeks & reads/second (%ld seeks & reads in %ld ms)\n",seekreads*1000/timing,seekreads,timing);
  536.           }
  537.           else {
  538.             printf("Random seek/reads of %5ld bytes in\n",readsize);
  539.             printf("                   %7ld byte file : %5ld",filesize,seekreads*1000/timing);
  540.  
  541.             if(arglist.nounits==0) {
  542.               printf(" times/second");
  543.             }
  544.             printf("\n");
  545.           }
  546.         }
  547.       }
  548.  
  549.       Close(fh);
  550.       DeleteFile("seekread.tst");
  551.     }
  552.     else {
  553.       errorcode=IoErr();
  554.     }
  555.     FreeVec(mem);
  556.   }
  557.   else {
  558.     errorcode=ERROR_NO_FREE_STORE;
  559.   }
  560.  
  561.   return(errorcode);
  562. }
  563.  
  564.  
  565.  
  566. LONG test_read(ULONG readsize,ULONG filesize) {
  567.   LONG errorcode=0;
  568.   UBYTE *mem;
  569.   BPTR fh;
  570.  
  571.   if(filesize<=readsize) {
  572.     return(ERROR_NO_FREE_STORE);
  573.   }
  574.  
  575.   if((mem=AllocVec(readsize,0))!=0) {
  576.     if((fh=Open("read.tst",MODE_NEWFILE))!=0) {
  577.       if((errorcode=extendfile(fh,filesize))==0) {
  578.         ULONG reads=0;
  579.         ULONG offset=0;
  580.  
  581.         starttimer();
  582.  
  583.         do {
  584.           if(Read(fh,mem,readsize)!=readsize) {
  585.             errorcode=IoErr();
  586.             break;
  587.           }
  588.  
  589.           offset+=readsize;
  590.  
  591.           if(offset+readsize>filesize) {
  592.             if(Seek(fh,0,OFFSET_BEGINNING)==-1) {
  593.               errorcode=IoErr();
  594.               break;
  595.             }
  596.             offset=0;
  597.           }
  598.  
  599.           reads++;
  600.         } while(finished()==FALSE);
  601.  
  602.         if(errorcode==0) {
  603.           if(arglist.verbose!=0) {
  604.             printf("Read       : Reads %ld bytes at a time from a file of %ld bytes.\n",readsize,filesize);
  605.             printf("             %ld kB/second (%ld reads in %ld ms)\n",(LONG)((double)reads*1000.0/(double)timing*(double)readsize/1024.0),reads,timing);
  606.           }
  607.           else {
  608.             printf("Read data using %7ld byte buffer  : %5ld",readsize,(LONG)((double)reads*1000.0/(double)timing*(double)readsize/1024.0));
  609.  
  610.             if(arglist.nounits==0) {
  611.               printf(" kB/second");
  612.             }
  613.             printf("\n");
  614.           }
  615.         }
  616.       }
  617.  
  618.       Close(fh);
  619.       DeleteFile("read.tst");
  620.     }
  621.     else {
  622.       errorcode=IoErr();
  623.     }
  624.     FreeVec(mem);
  625.   }
  626.   else {
  627.     errorcode=ERROR_NO_FREE_STORE;
  628.   }
  629.  
  630.   return(errorcode);
  631. }
  632.  
  633.  
  634.  
  635. LONG test_delayedread(ULONG readsize,ULONG filesize) {
  636.   LONG errorcode=0;
  637.   UBYTE *mem;
  638.   BPTR fh;
  639.  
  640.   if(filesize<=readsize) {
  641.     return(ERROR_NO_FREE_STORE);
  642.   }
  643.  
  644.   if((mem=AllocVec(readsize,0))!=0) {
  645.     if((fh=Open("read.tst",MODE_NEWFILE))!=0) {
  646.       if((errorcode=extendfile(fh,filesize))==0) {
  647.         ULONG reads=0;
  648.         ULONG offset=0;
  649.  
  650.         starttimer();
  651.  
  652.         do {
  653.           if(Read(fh,mem,readsize)!=readsize) {
  654.             errorcode=IoErr();
  655.             break;
  656.           }
  657.  
  658.           offset+=readsize;
  659.  
  660.           if(offset+readsize>filesize) {
  661.             if(Seek(fh,0,OFFSET_BEGINNING)==-1) {
  662.               errorcode=IoErr();
  663.               break;
  664.             }
  665.             offset=0;
  666.           }
  667.  
  668.           Delay(25);
  669.  
  670.           reads++;
  671.         } while(finished()==FALSE);
  672.  
  673.         if(errorcode==0) {
  674.           timing-=500*reads;  /* Substract the delays. */
  675.           printf("DelayedRead: Reads %ld bytes at a time from a file of %ld bytes with a 0.5 second delay between reads.\n",readsize,filesize);
  676.           printf("             %ld kB/second (%ld reads in %ld ms)\n",(LONG)((double)reads*1000.0/(double)timing*(double)readsize/1024.0),reads,timing);
  677.         }
  678.       }
  679.  
  680.       Close(fh);
  681.       DeleteFile("read.tst");
  682.     }
  683.     else {
  684.       errorcode=IoErr();
  685.     }
  686.     FreeVec(mem);
  687.   }
  688.   else {
  689.     errorcode=ERROR_NO_FREE_STORE;
  690.   }
  691.  
  692.   return(errorcode);
  693. }
  694.  
  695.  
  696.  
  697. LONG test_stationaryread(ULONG readsize) {
  698.   LONG errorcode=0;
  699.   UBYTE *mem;
  700.   BPTR fh;
  701.  
  702.   if((mem=AllocVec(readsize,0))!=0) {
  703.     if((fh=Open("statread.tst",MODE_NEWFILE))!=0) {
  704.       if((errorcode=extendfile(fh,readsize))==0) {
  705.         ULONG reads=0;
  706.  
  707.         starttimer();
  708.  
  709.         do {
  710.           if(Read(fh,mem,readsize)!=readsize) {
  711.             errorcode=IoErr();
  712.             break;
  713.           }
  714.  
  715.           if(Seek(fh,0,OFFSET_BEGINNING)==-1) {
  716.             errorcode=IoErr();
  717.             break;
  718.           }
  719.  
  720.           reads++;
  721.         } while(finished()==FALSE);
  722.  
  723.         if(errorcode==0) {
  724.           printf("Stat.Read  : Reads the same %ld bytes each time.\n",readsize);
  725.           printf("             %ld kB/second (%ld stationary reads in %ld ms)\n",(LONG)((double)reads*1000.0/(double)timing*(double)readsize/1024.0),reads,timing);
  726.         }
  727.       }
  728.  
  729.       Close(fh);
  730.       DeleteFile("statread.tst");
  731.     }
  732.     else {
  733.       errorcode=IoErr();
  734.     }
  735.     FreeVec(mem);
  736.   }
  737.   else {
  738.     errorcode=ERROR_NO_FREE_STORE;
  739.   }
  740.  
  741.   return(errorcode);
  742. }
  743.  
  744.  
  745.  
  746.  
  747. LONG test_write(ULONG writesize) {
  748.   LONG errorcode=0;
  749.   UBYTE *mem;
  750.   BPTR fh;
  751.  
  752.   if((mem=AllocVec(writesize,0))!=0) {
  753.     if((fh=Open("write.tst",MODE_NEWFILE))!=0) {
  754.       ULONG writes=0;
  755.  
  756.       starttimer();
  757.  
  758.       do {
  759.         if(Write(fh,mem,writesize)!=writesize) {
  760.           errorcode=IoErr();
  761.           break;
  762.         }
  763.  
  764.         writes++;
  765.       } while(finished()==FALSE);
  766.  
  767.       if(errorcode==0) {
  768.         if(arglist.verbose!=0) {
  769.           printf("Write      : Writes %ld bytes at a time to a file.\n",writesize);
  770.           printf("             %ld kB/second (%ld writes in %ld ms)\n",(LONG)((double)writes*1000.0/(double)timing*(double)writesize/1024.0),writes,timing);
  771.         }
  772.         else {
  773.           printf("Write data using %7ld byte buffer : %5ld",writesize,(LONG)((double)writes*1000.0/(double)timing*(double)writesize/1024.0));
  774.  
  775.           if(arglist.nounits==0) {
  776.             printf(" kB/second");
  777.           }
  778.           printf("\n");
  779.         }
  780.       }
  781.  
  782.       Close(fh);
  783.       DeleteFile("write.tst");
  784.     }
  785.     else {
  786.       errorcode=IoErr();
  787.     }
  788.     FreeVec(mem);
  789.   }
  790.   else {
  791.     errorcode=ERROR_NO_FREE_STORE;
  792.   }
  793.  
  794.   return(errorcode);
  795. }
  796.  
  797.  
  798.  
  799. LONG test_createfiles() {
  800.   LONG errorcode=0;
  801.   BPTR fh;
  802.   ULONG files=0;
  803.   UBYTE filename[16];
  804.  
  805.   starttimer();
  806.  
  807.   do {
  808.     sprintf(filename,"cf%06ld.tst",files);
  809.     filename[12]=0;
  810.  
  811.     if((fh=Open(filename,MODE_NEWFILE))==0) {
  812.       errorcode=IoErr();
  813.       break;
  814.     }
  815.  
  816.     Close(fh);
  817.  
  818.     files++;
  819.   } while(finished()==FALSE);
  820.  
  821.   if(errorcode==0) {
  822.     printf("CreateFiles: Creates empty files.\n");
  823.     printf("             %ld files created/second (%ld files created in %ld ms)\n",files*1000/timing,files,timing);
  824.   }
  825.  
  826.   while(files-->0) {
  827.     sprintf(filename,"cf%06ld.tst",files);
  828.     filename[12]=0;
  829.     DeleteFile(filename);
  830.   };
  831.  
  832.   return(errorcode);
  833. }
  834.  
  835.  
  836.  
  837. LONG testfiles_dirscan() {
  838.   struct FileInfoBlock *fib;
  839.   ULONG entries=0;
  840.   LONG errorcode=0;
  841.  
  842.   if((fib=AllocDosObjectTags(DOS_FIB,0))!=0) {
  843.     if(Examine(maindirlock,fib)!=DOSFALSE) {
  844.  
  845.       starttimer();
  846.  
  847.       do {
  848.         if(ExNext(maindirlock,fib)==DOSFALSE) {
  849.           errorcode=IoErr();
  850.           if(errorcode!=ERROR_NO_MORE_ENTRIES) {
  851.             break;
  852.           }
  853.  
  854.           if(Examine(maindirlock,fib)==DOSFALSE) {
  855.             errorcode=IoErr();
  856.             break;
  857.           }
  858.  
  859.           errorcode=0;
  860.         }
  861.  
  862.         entries++;
  863.       } while(finished()==FALSE);
  864.     }
  865.     else {
  866.       errorcode=IoErr();
  867.     }
  868.  
  869.     FreeDosObject(DOS_FIB,fib);
  870.   }
  871.   else {
  872.     errorcode=ERROR_NO_FREE_STORE;
  873.   }
  874.  
  875.   if(errorcode==0) {
  876.     if(arglist.verbose!=0) {
  877.       printf("DirScan    : Scans all files in a directory.\n");
  878.       printf("             %ld files/second (%ld files in %ld ms)\n",entries*1000/timing,entries,timing);
  879.     }
  880.     else {
  881.       printf("Scan all files in a directory        : %5ld",entries*1000/timing);
  882.  
  883.       if(arglist.nounits==0) {
  884.         printf(" files/second");
  885.       }
  886.       printf("\n");
  887.     }
  888.   }
  889.  
  890.   return(errorcode);
  891. }
  892.  
  893.  
  894.  
  895. LONG testfiles_openclose() {
  896.   ULONG openscloses=0;
  897.   LONG errorcode=0;
  898.   UBYTE filename[16];
  899.   BPTR fh;
  900.  
  901.   starttimer();
  902.  
  903.   do {
  904.     sprintf(filename,"tf%06ld.tst",rangerandom(files)+1);
  905.  
  906.     if((fh=Open(filename,MODE_OLDFILE))!=0) {
  907.       Close(fh);
  908.     }
  909.     else {
  910.       errorcode=IoErr();
  911.     }
  912.  
  913.     openscloses++;
  914.   } while(finished()==FALSE);
  915.  
  916.   if(errorcode==0) {
  917.     if(arglist.verbose!=0) {
  918.       printf("Open&Close : Opens a random file and closes it again.\n");
  919.       printf("             %ld opens & closes/second (%ld opens & closes in %ld ms)\n",openscloses*1000/timing,openscloses,timing);
  920.     }
  921.     else {
  922.       printf("Open and close a random file         : %5ld",openscloses*1000/timing);
  923.  
  924.       if(arglist.nounits==0) {
  925.         printf(" files/second");
  926.       }
  927.       printf("\n");
  928.     }
  929.   }
  930.  
  931.   return(errorcode);
  932. }
  933.  
  934.  
  935.  
  936. LONG testfiles_lockunlock() {
  937.   ULONG locksunlocks=0;
  938.   LONG errorcode=0;
  939.   UBYTE filename[16];
  940.   BPTR lock;
  941.  
  942.   starttimer();
  943.  
  944.   do {
  945.     sprintf(filename,"tf%06ld.tst",rangerandom(files)+1);
  946.  
  947.     if((lock=Lock(filename,SHARED_LOCK))!=0) {
  948.       UnLock(lock);
  949.     }
  950.     else {
  951.       errorcode=IoErr();
  952.     }
  953.  
  954.     locksunlocks++;
  955.   } while(finished()==FALSE);
  956.  
  957.   if(errorcode==0) {
  958.     if(arglist.verbose!=0) {
  959.       printf("Lock&Unlock: Locks a random file and unlocks it again.\n");
  960.       printf("             %ld locks & unlocks/second (%ld locks & unlocks in %ld ms)\n",locksunlocks*1000/timing,locksunlocks,timing);
  961.     }
  962.     else {
  963.       printf("Lock and unlock a random file        : %5ld",locksunlocks*1000/timing);
  964.  
  965.       if(arglist.nounits==0) {
  966.         printf(" files/second");
  967.       }
  968.       printf("\n");
  969.     }
  970.   }
  971.  
  972.   return(errorcode);
  973. }
  974.  
  975.  
  976.  
  977. LONG testfiles_deletefiles() {
  978.  
  979.   starttimer();
  980.  
  981.   deletetestfiles();
  982.  
  983.   endtimer();
  984.  
  985.   if(arglist.verbose!=0) {
  986.     printf("DeleteFiles: Deletes %ld files.\n",files);
  987.     printf("             %ld files deleted/second (%ld files deleted in %ld ms)\n",files*1000/timing,files,timing);
  988.   }
  989.   else {
  990.     printf("Deletes %5ld files                  : %5ld",files,files*1000/timing);
  991.  
  992.     if(arglist.nounits==0) {
  993.       printf(" files/second");
  994.     }
  995.     printf("\n");
  996.   }
  997.  
  998.   return(0);
  999. }
  1000.  
  1001.  
  1002.  
  1003. LONG testfiles_createfiles(ULONG filesize) {
  1004.   LONG errorcode;
  1005.  
  1006.   starttimer();
  1007.  
  1008.   errorcode=createtestfiles(filesize);
  1009.  
  1010.   endtimer();
  1011.  
  1012.   if(errorcode==0) {
  1013.     if(arglist.verbose!=0) {
  1014.       printf("CreateFiles: Creates %ld files of %ld bytes.\n",files,filesize);
  1015.       printf("             %ld files created/second (%ld files created in %ld ms)\n",files*1000/timing,files,timing);
  1016.     }
  1017.     else {
  1018.       printf("Creates %5ld files of %7ld bytes : %5ld",files,filesize,files*1000/timing);
  1019.  
  1020.       if(arglist.nounits==0) {
  1021.         printf(" files/second");
  1022.       }
  1023.       printf("\n");
  1024.     }
  1025.   }
  1026.  
  1027.   return(errorcode);
  1028. }
  1029.  
  1030.  
  1031.  
  1032. LONG testfiles_load() {
  1033.   ULONG loads=0;
  1034.   LONG errorcode=0;
  1035.   UBYTE filename[16];
  1036.   BPTR fh;
  1037.   UBYTE *mem;
  1038.  
  1039.   if((mem=AllocVec(131072,0))!=0) {
  1040.  
  1041.     starttimer();
  1042.  
  1043.     do {
  1044.       sprintf(filename,"tf%06ld.tst",rangerandom(files)+1);
  1045.  
  1046.       if((fh=Open(filename,MODE_OLDFILE))!=0) {
  1047.  
  1048.         while(Read(fh,mem,131072)==131072) {
  1049.         }
  1050.  
  1051.         Close(fh);
  1052.       }
  1053.       else {
  1054.         errorcode=IoErr();
  1055.       }
  1056.  
  1057.       loads++;
  1058.     } while(finished()==FALSE);
  1059.  
  1060.     FreeVec(mem);
  1061.  
  1062.     if(errorcode==0) {
  1063.       if(arglist.verbose!=0) {
  1064.         printf("Load       : Opens a random file, loads it and closes it again.\n");
  1065.         printf("             %ld loads/second (%ld loads in %ld ms)\n",loads*1000/timing,loads,timing);
  1066.       }
  1067.       else {
  1068.         printf("Load a random file                   : %5ld",loads*1000/timing);
  1069.  
  1070.         if(arglist.nounits==0) {
  1071.           printf(" files/second");
  1072.         }
  1073.         printf("\n");
  1074.       }
  1075.     }
  1076.   }
  1077.  
  1078.   return(errorcode);
  1079. }
  1080.  
  1081. /*
  1082.  
  1083. Creates 50000 files of 1048576 bytes : 10000 files/second
  1084. Open and close a random file         : 10000 files/second
  1085. Lock and unlock a random file        : 10000 files/second
  1086. Load a random file                   : 10000 files/second
  1087. Deletes 50000 files                  : 10000 files/second
  1088.  
  1089. Random seek/reads of 65536 bytes in
  1090.                    1048576 byte file : 10000 times/second
  1091.  
  1092. Read data using 1048576 byte buffer  : 10000 kB/second
  1093. Write data using 1048576 byte buffer : 10000 kB/second
  1094.  
  1095. */
  1096.